package com.owg.jigsaw.javafx;

import java.util.LinkedHashSet;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;

public class ActionSource
{
	private LinkedHashSet<EventHandler<? super ActionEvent>> listeners = new LinkedHashSet<>(); 
	
	public void fireEvents()
	{
		ActionEvent e = new ActionEvent(this, null);
		for(EventHandler<? super ActionEvent> l : listeners)
		{
			l.handle(e);
		}
	}
	
	public void addActionListener(EventHandler<? super ActionEvent> l)
	{
		listeners.add(l);
	}
	
	public boolean removeActionListener(EventHandler<? super ActionEvent> l)
	{
		return listeners.remove(l);
	}
}
